import Paging from '../../../wxjs/Paging.js'
import getLocation from '../../../wxjs/getLocation.js'
import navToNext from '../../../wxjs/navToNext.js'
import screen from '../../../wxjs/screen.js'
const app = getApp();

var pag = new Paging();

var data = {
  xhx_images: app.xhx_images,
  xhx_route: app.xhx_route,
  drops: [{
    id: 5,
    text: '全市',
    status: true,
  }, {
    id: 2,
    text: '门店类型',
  }, {
    id: 3,
    text: '时段',
  }]
};

var currentPage = {
  data,
  reqUrl: app.serAddrs.getGymList,
  typeParams: {}, //获取筛选标签参数
  onLoad,
  checkDrop, //下拉选择
  completeLocation, //定位获取完成（成功，失败）
  onShareAppMessage: function() {}
};

var page = Object.assign({}, pag.func(), getLocation, navToNext, screen, currentPage);

Page(page)

function onLoad(options) {
  const that = this;
  const uuid = options && options.uuid || "";

  // 异步获取用户信息
  app.xlogin.getUser();

  if (uuid) {
    wx.navigateTo({
      url: `${app.xhx_route.storeDetails}?uuid=${uuid}`,
    })
  }

  that.getLocation();
}

function checkDrop(event) {
  const that = this;
  const id = event.detail.id;

  that.typeParams.type = id || 0;
  that.setData({
    tabId: id
  })

  that.getSearchLabelByType();
}

function completeLocation(res) {
  const that = this;
  let latitude = res.latitude || '';
  let longitude = res.longitude || '';

  that.listParams.latitude = latitude;
  that.listParams.longitude = longitude;
  that.listParams.areas = [];
  that.listParams.gymTypeIds = [];
  that.listParams.intervalTimes = [];
  that.listParams.tGoodsLabelNameUuids = [];
  that.listParams.tGymUuids = [];
  that.listParams.isShadowOver = 0;

  that.typeParams.latitude = latitude;
  that.typeParams.longitude = longitude;
  // 初始化
  that.pageListInit();

  that.setData({
    latitude,
    longitude
  })
}